<?php
// 检查签到状态和积分

// 数据库连接
$host = '113.44.136.17';
$port = '3306';
$dbname = 'qiandao';
$username = 'qiandao';
$password = 'NGbks3HWx5PhSxDX';

try {
    $pdo = new PDO("mysql:host={$host};port={$port};dbname={$dbname};charset=utf8mb4", $username, $password);
    $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
    
    echo "=== 会员信息 ===\n";
    $stmt = $pdo->query("SELECT id, name, card_no, total_points, available_points, last_checkin_time FROM checkin_member WHERE id=1");
    $member = $stmt->fetch(PDO::FETCH_ASSOC);
    print_r($member);
    
    echo "\n=== 最近5条签到记录 ===\n";
    $stmt = $pdo->query("
        SELECT id, member_id, start_time, end_time, duration_minutes, points, status, invalid_reason, create_time 
        FROM checkin_record 
        WHERE member_id=1 
        ORDER BY id DESC 
        LIMIT 5
    ");
    $records = $stmt->fetchAll(PDO::FETCH_ASSOC);
    foreach ($records as $record) {
        echo "ID: {$record['id']}, ";
        echo "开始: {$record['start_time']}, ";
        echo "结束: {$record['end_time']}, ";
        echo "时长: {$record['duration_minutes']}分钟, ";
        echo "积分: {$record['points']}, ";
        echo "状态: {$record['status']} ";
        echo "(1=完成/2=无效/3=进行中)";
        if ($record['invalid_reason']) {
            echo ", 原因: {$record['invalid_reason']}";
        }
        echo "\n";
    }
    
    echo "\n=== 最近5条签到日志 ===\n";
    $stmt = $pdo->query("
        SELECT id, member_id, member_name, check_time, is_success 
        FROM system_checkin_log 
        WHERE member_id=1 
        ORDER BY id DESC 
        LIMIT 5
    ");
    $logs = $stmt->fetchAll(PDO::FETCH_ASSOC);
    foreach ($logs as $log) {
        echo "ID: {$log['id']}, ";
        echo "时间: {$log['check_time']}, ";
        echo "成功: {$log['is_success']}\n";
    }
    
    echo "\n=== 积分明细记录 ===\n";
    $stmt = $pdo->query("
        SELECT id, points, type, source, remark, create_time 
        FROM checkin_points_record 
        WHERE member_id=1 
        ORDER BY id DESC 
        LIMIT 5
    ");
    $pointsRecords = $stmt->fetchAll(PDO::FETCH_ASSOC);
    if (empty($pointsRecords)) {
        echo "没有积分记录\n";
    } else {
        foreach ($pointsRecords as $pr) {
            echo "ID: {$pr['id']}, ";
            echo "积分: {$pr['points']}, ";
            echo "类型: {$pr['type']} (1=获得/2=消费/3=调整), ";
            echo "来源: {$pr['source']}, ";
            echo "备注: {$pr['remark']}, ";
            echo "时间: {$pr['create_time']}\n";
        }
    }
    
    echo "\n=== 系统配置 ===\n";
    $stmt = $pdo->query("SELECT * FROM checkin_setting WHERE store_id=0");
    $config = $stmt->fetch(PDO::FETCH_ASSOC);
    echo "单位分钟: {$config['unit_minutes']}\n";
    echo "取整方式: {$config['rounding']}\n";
    echo "超时作废: {$config['timeout_minutes']}分钟\n";
    echo "时间段配置: {$config['time_slots']}\n";
    
} catch (PDOException $e) {
    echo "数据库错误: " . $e->getMessage() . "\n";
}

